import pandas as pd
import psycopg2

# 读取 Excel 文件
excel_file_path = 'your_excel_file.xlsx'
df = pd.read_excel(excel_file_path)

# 连接到 PostgreSQL 数据库
conn = psycopg2.connect(
    database="a2513220218",
    user="a2513220218",
    password="xawl-6043",
    host="172.16.137.39",
    port="5432"
)


# 创建游标
cur = conn.cursor()

# 将数据插入到数据库表中（假设表名为 your_table_name）
for index, row in df.iterrows():
    # 根据实际情况调整列名和数据类型
    cur.execute("INSERT INTO "S-T" (sno,sname,ssex,sage,sdept)
VALUES('201215108','曾华','男',18,'IS'),
    ('201215105','匡明','男',19,'MA'),
    ('201215107','王丽','女',21,'CS'),
    ('201215101','李军','男',20,'IS'),
    ('201215109','王芳','女',18,'MA'),
    ('201215103','陆君','男',20,'IS')", 
    (row['column1'], row['column2'], row['column3'],...))

# 提交事务
conn.commit()

# 关闭游标和连接
cur.close()
conn.close()